<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sj" tagdir="/WEB-INF/tags/spring-jquery-tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<link href="<c:url value='/css/tablesorter.css' />" rel="stylesheet" type="text/css"/>
<link href="<c:url value='/css/jquery.tablesorter.pager.css' />" rel="stylesheet" type="text/css"/>
<link href="<c:url value='/css/dhtmlxcombo_view.css' />" rel="stylesheet" type="text/css"/>

<script type="text/javascript">
	$(document).ready(function() {
		$('#editPartnergrantForm input, #editPartnergrantForm select').keypress(function(e) {
      		if(e.which == 13) {      
            	jQuery('#loginFormSubmit').click();
            	return false;
       		}
   		});
		
		$('#pageTitle').text('<spring:message code="findPartnergrant.heading" />');
		$(".tablesorter").tablesorter().tablesorterPager({container: $("#pager")});	 
		 $('#loginFormSubmit').click(function() {		
		  var v1= $('#projectID').val();
		  var v2= $('#acronym').val();
		  var v3= $('#partner\\.id').val();
		  var v4= $('#projectTitle').val();
		  var v5= $('#programOfficer\\.id').val();
		  var v6= $('#region\\.id').val();
		  var v7= $('#country\\.id').val();
		  var v8= $('#cipeprojectstatus\\.id').val();
		  var v9= $('#initialProjectStartDate').val();
		  var v10= $('#finalProjectStartDate').val();
		  
		  var v11= $('#initialProjectEndDate').val();
		  var v12= $('#finalProjectEndDate').val();
		  var v13= $('#initialManagementFunds').val();
		  var v14= $('#finalManagementFunds').val();
		// alert(v14);
		 if(v1!='' || v2!='' || v3!=''|| v4!='' || v5!='' || v6!='' || v7!='' || v8!='' || v9!='' || v10!='' || v11!='' || v12!='' || v13!='' || v14!=''){		    
		    return true;
		  }
		 alert("Please enter at least one filter criteria");
		 return false;
		});
		
		
		$("#editPartnergrantForm").validate({
			rules : {
				name : {
					required : true
				}
			}
		});
		$('.edit-partnergrant-link').click(function() {
			loadDiv('content', 'showEditPartnergrantView.do?id=' + $(this).attr('partnergrantId'));
		});
		$(function() {
			$("#initialProjectStartDate").datepicker();
		});
		$(function() {
			$("#finalProjectStartDate").datepicker();
		});
		$(function() {
			$("#initialProjectEndDate").datepicker();
		});
		$(function() {
			$("#finalProjectEndDate").datepicker();
		});
	});
	$('.view-knowledgemanagementsearch-link').click(function() {
		loadDiv('content', 'findKnowledgeManagement.do');
	});
	$('.close-button').click(function() {
		loadDiv('content', 'refreshDashboard.do');
	});
     

   /*	 
 	$('#check-all').click(function() {       
        var checkBox = $('#partnergrid input:checkbox');
        for(var i = 0; i < checkBox.length; i++) {
     	   checkBox[i].checked = this.checked;
        }
 	});*/
</script>
<div id="findPartnergrantDiv">
	<form:form name="editPartnergrantForm" id="editPartnergrantForm" action="findResultPartnergrant.do" method="post" modelAttribute="cipeproject">
		<form:hidden path="id" />
		<div class="main_form">
			<div class="form_head">
				<div class="floatL" style="padding-top:5px;">
					<a href="#" class="view-knowledgemanagementsearch-link blue_btn floatR"><spring:message code="findPartnergrant.link.viewKnowledgeManagement" /></a>
				</div>
	    		<a href="javascript://" class="close-button gray_btn floatR" tabindex="-1">Close Form</a>
	    		<br class="clear" />
	    	</div>
	    	<div class="form_cont">
				<table cellspacing="5" width="100%">				  
					<tr class="row">
						<td class="input-field" colspan="5"><%@ include file="/common/messages.jsp"%></td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editPartnergrant.label.projectID" /></td>
						<td class="input-field">
							<form:input path="projectID" cssClass="input-full-width text_white" />
							<form:errors path="projectID" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editPartnergrant.label.acronym" /></td>
						<td class="input-field">
							<form:input path="acronym" cssClass="input-full-width text_white" />
							<form:errors path="acronym" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editPartnergrant.label.partner" /></td>
						<td class="input-field">
							<form:select path="partner.id" cssClass="text_white">
								<form:option value="" label="Select" />
								<form:options items="${partnerList}" itemValue="id" itemLabel="partnerName" />
							</form:select>
							<form:errors path="partner.id" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editPartnergrant.label.projectTitle" /></td>
						<td class="input-field">
							<form:input path="projectTitle" cssClass="input-full-width text_white" />
							<form:errors path="projectTitle" cssClass="error" />
						</td>
					</tr>
					
					<tr class="row">
						<td class="label" nowrap><spring:message code="editPartnergrant.label.programOfficer" /></td>
						<td class="input-field">
							<form:select path="programOfficer.id" cssClass="text_white">
								<form:option value="" label="Select" />
								<form:options items="${programOfficerList}" itemValue="id" itemLabel="fullName" />
							</form:select>
							<form:errors path="programOfficer.id" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>

						<td class="label"><spring:message code="editPartnergrant.label.region" /></td>
						<td class="input-field">
							<form:select path="region.id" cssClass="text_white">
								<form:option value="" label="Select" />
								<form:options items="${regionList}" itemValue="id" itemLabel="displayName" />
							</form:select>
							<form:errors path="region.id" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editPartnergrant.label.country" /></td>
						<td class="input-field">
							<form:select path="country.id" cssClass="text_white">
								<form:option value="" label="Select" />
								<form:options items="${countryList}" itemValue="id" itemLabel="displayName" />
							</form:select>
							<form:errors path="country.id" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editPartnergrant.label.grantStatus" /></td>
						<td class="input-field">
							<form:select path="cipeprojectstatus.id" cssClass="text_white">
								<form:option value="" label="Select" />
								<form:options items="${cipeprojectstatusList}" itemValue="id" itemLabel="displayName" />
							</form:select>
							<form:errors path="cipeprojecttype.id" cssClass="error" />
						</td>
					</tr>
					<!-- 
					<tr class="row">
						<td class="label"><spring:message code="editPartnergrant.label.fiscalYear" /></td>
						<td class="input-field"><form:input path="fiscalYear" cssClass="input-full-width text_white" /></td>
						<td><form:errors path="fiscalYear" cssClass="error" /></td>
					</tr>
					 -->
					<tr class="row">
						<td class="label"><spring:message code="editPartnergrant.label.startDateBetween" /></td>
						<td class="input-field">
							<form:input path="initialProjectStartDate" cssClass="input-full-width text_white" />
							<form:errors path="initialProjectStartDate" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="label.and" /></td>
						<td class="input-field">
							<form:input path="finalProjectStartDate" cssClass="input-full-width text_white" />
							<form:errors path="finalProjectStartDate" cssClass="error" />
						</td>
					</tr>
					<tr>
						<td class="label"><spring:message code="editPartnergrant.label.endDateBetween" /></td>
						<td class="input-field">
							<form:input path="initialProjectEndDate" cssClass="input-full-width text_white" />
							<form:errors path="initialProjectEndDate" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="label.and" /></td>
						<td class="input-field">
							<form:input path="finalProjectEndDate" cssClass="input-full-width text_white" />
							<form:errors path="finalProjectEndDate" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editPartnergrant.label.managementFundsBetween" /></td>
						<td class="input-field">
							<form:input path="initialManagementFunds" cssClass="input-full-width text_white" />
							<form:errors path="initialManagementFunds" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="label.and" /></td>
						<td class="input-field">
							<form:input path="finalManagementFunds" cssClass="input-full-width text_white" />
							<form:errors path="finalManagementFunds" cssClass="error" />
						</td>
					</tr>
					<tr>
	                	<td class="label">&nbsp;</td>
	                	<td>&nbsp;</td>
	                	<td width="50">&nbsp;</td>
	                	<td class="label">&nbsp;</td>
	                	<td></td>
	              	</tr>					
					<tr class="row">
						<td class="input-field" align="center" colspan="5">
							<sj:submit cssClass="blue_btn" id="loginFormSubmit" target="findPartnergrantDiv" key="findPartnergrant.button.search" validate="true" tabindex="-1"/>
							<input class="blue_btn" type="reset" value="<spring:message code='findPartnergrant.button.reset' />" tabindex="-1"/>
						</td>
					</tr>
				</table>
				<div id="cipeprojectListDiv" class="hastable" style="overflow: auto">
				<c:if test="${ !empty cipeprojectList}">
				<%@ include file="/common/pager.jsp" %>
				</c:if>
					<table class="tablesorter">
				    <c:choose>
						<c:when test="${!empty cipeprojectList}">			
							<thead>
							<c:if test="${messgae!='null'}">
									<tr>
									<th colspan="15"><font size="4"><c:out value="${message}"></c:out></font></th>
									</tr>
									</c:if>
								<!--tr><th nowrap><input type="checkbox" id="check-all">&#10;<spring:message code="common.select.all"/></th-->
									<th nowrap><spring:message code="partnergrantlist.table.heading.projectID" /></th>
									<th><spring:message code="partnergrantlist.table.heading.projectSponsor" /></th>
									<th><spring:message code="partnergrantlist.table.heading.acronym" /></th>									
									<th><spring:message code="partnergrantlist.table.heading.budget" /></th>
									<th><spring:message code="partnergrantlist.table.heading.disbursed" /></th>
									<th><spring:message code="partnergrantlist.table.heading.balance" /></th>
									<th nowrap><spring:message code="partnergrantlist.table.heading.projectTitle" /></th>
									<th><spring:message code="partnergrantlist.table.heading.startDate" /></th>
									<th><spring:message code="partnergrantlist.table.heading.endDate" /></th>
									<th><spring:message code="partnergrantlist.table.heading.status" /></th>
									<th nowrap><spring:message code="partnergrantlist.table.heading.ingrants" /></th>
									<th nowrap><spring:message code="partnergrantlist.table.heading.agreement" /></th>
									<th nowrap><spring:message code="partnergrantlist.table.heading.autho" /></th>
									<th nowrap><spring:message code="partnergrantlist.table.heading.bank" /></th>
									<!-- <th><spring:message code="partnergrantlist.table.heading.type"/></th>
								<th nowrap><spring:message code="partnergrantlist.table.heading.programOfficer" /></th>
								<th nowrap><spring:message code="partnergrantlist.table.heading.region" /></th>
								<th nowrap><spring:message code="partnergrantlist.table.heading.country" /></th>
								<th nowrap><spring:message code="partnergrantlist.table.heading.managementFunds" /></th> -->
									<%--<th><spring:message code="partnergrantlist.table.heading.edit" /></th> --%>
								</tr>
							</thead>			
						<tbody id="partnergrid">
							<c:forEach items="${cipeprojectList}" var="cipeproject">
								<!--tr><td ><input type="checkbox" name="check_element" value="${cipeproject.id}"></td-->
									<td><a href="javascript://" class="edit-partnergrant-link" partnergrantId="${cipeproject.id}"> ${cipeproject.projectID}</a></td>
									<td>${cipeproject.partner.partnerName}</td>
									<td>${cipeproject.acronym}</td>									
									<%--<td><a href="javascript://" class="edit-partnergrant-link" partnergrantId="${cipeproject.id}">${cipeproject.projectID}</a></td> --%>
									<td><fmt:formatNumber type="currency" value="${cipeproject.partnerBudgetAmount}" pattern="$#,##0;"/></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.partnerDisbursedAmount}" pattern="$#,##0;"/></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.partnerBalanceAmount}" pattern="$#,##0;"/></td>
									<td>${cipeproject.projectTitle}</td>
									<td><fmt:formatDate pattern="MM-dd-yyyy" value="${cipeproject.projectStartDate}" /></td>
									<td><fmt:formatDate pattern="MM-dd-yyyy" value="${cipeproject.projectEndDate}" /></td>
									<td>${cipeproject.cipeprojectstatus.displayName}</td>
									<td>${cipeproject.receivedingrantsforapproval}</td>
									<td>${cipeproject.receiptOfSignedAgreement}</td>
									<td>${cipeproject.receiptOfSignatureAuthorization}</td>
									<td>${cipeproject.receiptOfBankInformation}</td>
									<!--<td>${cipeproject.cipeprojecttype.displayName}</td>
									<td>${cipeproject.programOfficer.fullName}</td>
									<td>${cipeproject.region.displayName}</td>
									<td>${cipeproject.country.displayName}</td>
									<td>${cipeproject.managementFunds}</td>-->
									<%--<td><a href="javascript://" class="edit-partnergrant-link" partnergrantId="${cipeproject.id}"><spring:message code="partnergrantlist.table.link.edit" /></a></td> --%>
								</tr>
							</c:forEach>
							
						    <!--tr align="center"><td align="left" colspan="12"><input type="button" class="blue_btn" name="view" value="View Selected Grants" align="center" tabindex="-1"></td></tr-->
							</c:when>
							<c:otherwise>
							<c:set  var="m" value="${message}"/>
								<c:if test="${! empty m}">
									<thead>
									<tr>
									<th colspan="12"><font size="4"><c:out value="${message}"></c:out></font></th>
									<tr><td colspan="14"> Your query has returned 0 records </td></tr>
									</thead>
								</c:if>	
							<c:if test="${ !empty param.action}">					  
								   <tr><td colspan="15"> Your query has returned 0 records </td></tr>
								 </c:if>  
							</c:otherwise>
							</c:choose>
						</tbody>
					</table>
					<div id="partnergrantListPager"></div>
				</div>
			</div>
		</div>					
	</form:form>
	</div>
</div>